package com.aqielife.demo.example.lambda;

import java.text.DecimalFormat;
import java.util.function.Function;

class MyMoney {
    private final int money;

    public MyMoney(int money) {
        this.money = money;
    }

    // 函数接口(输入int 输出 String)
    public void printMoney(Function<Integer, String> moneyFormat) {
        System.out.println("我的存款：" + moneyFormat.apply(this.money));
    }
}

public class MoneyDemo {

    public static void main(String[] args) {
        MyMoney me = new MyMoney(99999999);
        me.printMoney(i -> new DecimalFormat("#,###").format(i));
        /*Function<Integer, String> moneyFormat = i -> new DecimalFormat("#,###")
                .format(i);

        // 函数接口链式操作 º¯Êý½Ó¿ÚÁ´Ê½²Ù×÷
        me.printMoney(moneyFormat.andThen(s -> "人民币 " + s));*/
    }

}
